package com.um.jdy.app.shop.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.shop.entity.dto.GoodsCommentPageDTO;
import com.um.jdy.app.shop.entity.vo.GoodsCommentItemVO;
import com.um.jdy.app.shop.manager.GoodsCommentManager;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author renjunwei
 * @date 2020/9/19 09:37
 */
@Api(tags = "商品")
@RestController
@RequestMapping("/api/v1/goods/comment/")
@Validated
public class GoodsCommentController {

    @Autowired
    GoodsCommentManager goodsCommentManager;


    /**
     * 分页查询商品评价
     * @param dto
     * @return
     */
    @ApiOperation("分页查询商品评价")
    @GetMapping("page")
    public Response<Page<GoodsCommentItemVO>> getGoodsCommentPage(@Valid @ModelAttribute GoodsCommentPageDTO dto){
        return Response.success(goodsCommentManager.getGoodsCommentPage(dto));
    }

    /**
     * 点赞商品评价
     * @param id
     * @return
     */
    @SaCheckLogin
    @ApiOperation("点赞商品评价")
    @PostMapping("approve/{id}")
    public Response approve(@PathVariable String id){
        goodsCommentManager.approve(id);
        return Response.success();
    }

}
